package com.ruoyi.archives.service.impl;

import java.util.LinkedList;
import java.util.List;

import com.ruoyi.archives.domain.SysRelatives;
import com.ruoyi.archives.utile.DirectorRoleUtile;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.uuid.UuidUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.archives.mapper.SysTeacherRelativesMapper;
import com.ruoyi.archives.domain.SysTeacherRelatives;
import com.ruoyi.archives.service.ISysTeacherRelativesService;

/**
 * 教师亲属关系Service业务层处理
 * 
 * @author gzhankh
 * @date 2022-03-06
 */
@Service
public class SysTeacherRelativesServiceImpl implements ISysTeacherRelativesService 
{
    @Autowired
    private SysTeacherRelativesMapper sysTeacherRelativesMapper;


    @Autowired
    private DirectorRoleUtile directorRoleUtile;
    /**
     * 查询教师亲属关系
     * 
     * @param id 教师亲属关系主键
     * @return 教师亲属关系
     */
    @Override
    public SysTeacherRelatives selectSysTeacherRelativesById(String id)
    {
        return sysTeacherRelativesMapper.selectSysTeacherRelativesById(id);
    }

    /**
     * 查询教师亲属关系列表
     * 
     * @param sysTeacherRelatives 教师亲属关系
     * @return 教师亲属关系
     */
    @Override
    public List<SysTeacherRelatives> selectSysTeacherRelativesList(SysTeacherRelatives sysTeacherRelatives)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        int flag = directorRoleUtile.getTEDirectorRole(loginUser);
        List<SysTeacherRelatives> relativesList = sysTeacherRelativesMapper.selectSysTeacherRelativesList(sysTeacherRelatives);
        LinkedList<SysTeacherRelatives> sysRelativesTemp = new LinkedList<>();
        if(!SecurityUtils.isAdmin(loginUser.getUserId())&&flag==1){
            for (SysTeacherRelatives relatives : relativesList) {
                if(relatives.getArcNum().equals(loginUser.getUserId().toString())){
                    sysRelativesTemp.add(relatives);
                }
            }
            return sysRelativesTemp;
        }
        return sysTeacherRelativesMapper.selectSysTeacherRelativesList(sysTeacherRelatives);
    }

    /**
     * 新增教师亲属关系
     * 
     * @param sysTeacherRelatives 教师亲属关系
     * @return 结果
     */
    @Override
    public int insertSysTeacherRelatives(SysTeacherRelatives sysTeacherRelatives)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        sysTeacherRelatives.setId(UuidUtils.get8UUID());
        sysTeacherRelatives.setArcNum(loginUser.getUserId().toString());
        sysTeacherRelatives.setUserName(loginUser.getUsername());
        return sysTeacherRelativesMapper.insertSysTeacherRelatives(sysTeacherRelatives);
    }

    /**
     * 修改教师亲属关系
     * 
     * @param sysTeacherRelatives 教师亲属关系
     * @return 结果
     */
    @Override
    public int updateSysTeacherRelatives(SysTeacherRelatives sysTeacherRelatives)
    {
        return sysTeacherRelativesMapper.updateSysTeacherRelatives(sysTeacherRelatives);
    }

    /**
     * 批量删除教师亲属关系
     * 
     * @param ids 需要删除的教师亲属关系主键
     * @return 结果
     */
    @Override
    public int deleteSysTeacherRelativesByIds(String[] ids)
    {
        return sysTeacherRelativesMapper.deleteSysTeacherRelativesByIds(ids);
    }

    /**
     * 删除教师亲属关系信息
     * 
     * @param id 教师亲属关系主键
     * @return 结果
     */
    @Override
    public int deleteSysTeacherRelativesById(String id)
    {
        return sysTeacherRelativesMapper.deleteSysTeacherRelativesById(id);
    }
}
